import React, {Component} from 'react';

import './index.less';

import {base} from 'nc-lightapp-front';

const {
    NCModal,
    NCButton
} = base;

const {
    Header: NCModalHeader,
    Body: NCModalBody,
    Footer: NCModalFooter
} = NCModal;

class CreateNewReport extends Component {
    constructor(props) {
        super(props);

        this.onSubmit = this.onSubmit.bind(this);
        this.onCancel = this.onCancel.bind(this);
    }

    onCancel() {
        const {
            form,
            onCancel
        } = this.props;
        form.EmptyAllFormValue('rptcard');
        onCancel && onCancel();
    }

    onSubmit() {
        if(this.props.form.isCheckNow('rptcard')) {
            this.props.onSubmit && this.props.onSubmit();
        }
    }

    render() {
        const {
            visible, 
            language, 
            form,
            onFormAfterChange
        } = this.props;

        return (
            <NCModal
                show={visible}
                size="lg"
                onHide={this.onCancel}
                className="edit-report-modal-wrapper"
            >
                <NCModalHeader
                    closeButton={true}
                >
                    {language['hi6007-000197']/* 新建报表 */}
                </NCModalHeader>
                <NCModalBody>
                    <div className="edit-report-form-wrapper">
                        {form.createForm('rptcard', {
                            onAfterEvent: onFormAfterChange
                        })}
                    </div>
                </NCModalBody>
                <NCModalFooter>
                    <NCButton
                        colors="primary"
                        onClick={this.onSubmit}
                    >
                        {language['hi6007-000004']/* 确定 */}
                    </NCButton>
                    <NCButton
                        onClick={this.onCancel}
                    >
                        {language['hi6007-000005']/* 取消 */}
                    </NCButton>
                </NCModalFooter>
            </NCModal>
        );
    }
}

export default CreateNewReport;